package com.hnkywl.sts.action.sys;

import com.hnkywl.sts.entity.organ.Gsjg;
import com.hnkywl.sts.entity.sys.Gncz;
import com.hnkywl.sts.service.organ.GsjgService;
import com.hnkywl.sts.service.sys.GnczService;
import com.hnkywl.sts.service.xsgl.KcbjService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-5-31
 * Time: 下午3:09
 * To change this template use File | Settings | File Templates.
 */
@ParentPackage("default")
@Namespace("/sys/bjgl")
public class BjAction extends SimpleActionSupport {
    private GsjgService gsjgService;

    private KcbjService kcbjService;

    private Date currentDate;

    private String gsmc;

    private String gsId;

    private List<Map> bjList;

    private Integer count = 0;


    //功能操作
    private List<Gncz> gnczList;
    private GnczService gnczService;

    @Action("bjgl")
    public String bjgl() {
        gnczList = gnczService.findGnczByJsAndUrl(request.getServletPath());
        return SUCCESS;
    }

    @Action("bjDetail")
    public String bjDetail() {
        Date curdate = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(curdate);
        calendar.add(calendar.DATE, -1);//把日期往后增加一天.整数往后推,负数往前移动
        currentDate = calendar.getTime();
        String[] ids = gsId.split(",");
        if (count >= ids.length)
            count = 0;
        Gsjg gsjg = this.gsjgService.findGsjgDetail(Long.parseLong(ids[count]));
        gsmc = gsjg.getQc();
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = dateformat.parse(dateformat.format(currentDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        List bjrqList = new ArrayList();
        bjList = this.kcbjService.findAllKcbj(date, Long.parseLong(ids[count]), bjrqList);
        if (bjrqList.get(0) != null)
            currentDate = (Date) bjrqList.get(0);
        count++;
        return SUCCESS;
    }

    public Date getCurrentDate() {
        return currentDate;
    }

    public void setCurrentDate(Date currentDate) {
        this.currentDate = currentDate;
    }

    public String getGsmc() {
        return gsmc;
    }

    public void setGsmc(String gsmc) {
        this.gsmc = gsmc;
    }

    public String getGsId() {
        return gsId;
    }

    public void setGsId(String gsId) {
        this.gsId = gsId;
    }

    public List<Map> getBjList() {
        return bjList;
    }

    public void setBjList(List<Map> bjList) {
        this.bjList = bjList;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public List<Gncz> getGnczList() {
        return gnczList;
    }

    public void setGnczList(List<Gncz> gnczList) {
        this.gnczList = gnczList;
    }

    @Autowired
    public void setGnczService(GnczService gnczService) {
        this.gnczService = gnczService;
    }

    @Autowired
    public void setGsjgService(GsjgService gsjgService) {
        this.gsjgService = gsjgService;
    }

    @Autowired
    public void setKcbjService(KcbjService kcbjService) {
        this.kcbjService = kcbjService;
    }
}
